package org.testis.utils.middleware;

import org.orm.PersistentException;
import org.orm.PersistentTransaction;
import org.testis.orm.classes.T_test_log_details;

/**
 * 
 * @author nurhat
 */
public class LogDetail extends DbConnectionSupplier {

    public synchronized void commit() {
	try {
	    PersistentTransaction t = openDBConnection().beginTransaction();
	    try {
		t.commit();
	    } catch (PersistentException ex) {
		t.rollback();
		ex.printStackTrace();
	    }
	} catch (PersistentException ex) {
	    ex.printStackTrace();
	}
    }

    public synchronized void addLog(String logClass, String logLevel,
	    String message, String objectDescription, String dateExecuted,
	    String guid) {
	try {

	    T_test_log_details logDetails = new T_test_log_details();
	    logDetails.setGuid(guid);
	    logDetails.setLogClass(logClass);
	    logDetails.setLogLevel(logLevel);
	    logDetails.setMessage(message);
	    logDetails.setObjectDescription(objectDescription);

	    logDetails.setDateExecuted(dateExecuted);
	    logDetails.save();
	} catch (PersistentException ex) {
	    ex.printStackTrace();
	}

    }
}
